#include <stdio.h>
#include <algorithm>
#include <functional>

int main()
{
    int a[10], P;
    scanf("%d", &P);
    for (int i = 0; i < P; i++)
    {
        int t;
        scanf("%d", &t);
        for (int j = 0; j < 10; j++)
            scanf("%d", &a[j]);
        std::nth_element(a, a+2, a+10, std::greater<int>());
        printf("%d %d\n", t, a[2]);
    }
    return 0;
}